package com.huatai.exchange.impl;

import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.dal.dao.ExcExchangeRecordDAO;
import com.huatai.exchange.dal.model.ExcExchangeRecord;
import com.huatai.exchange.service.ExcExchangeRecordService;
import com.huatai.exchange.service.ExcuteExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcExchangeRecordServiceImpl implements ExcExchangeRecordService {

    @Autowired
    private ExcExchangeRecordDAO excExchangeRecordDAO;

    @Override
    public List<ExcExchangeRecord> queryExcExchangeRecordList(ExcExchangeRecord excExchangeRecord) throws BusinessException {
        List<ExcExchangeRecord> records = null;
        try {
            records = excExchangeRecordDAO.queryByModel(excExchangeRecord);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return records;
    }

    @Override
    public void addExcExchangeRecord(ExcExchangeRecord excExchangeRecord) throws BusinessException {
        try {
            excExchangeRecordDAO.insert(excExchangeRecord);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyExcExchangeRecord(ExcExchangeRecord excExchangeRecord) throws BusinessException {
        try {
            long num = excExchangeRecordDAO.updateById(excExchangeRecord) ;
            if(num == 0) {
                throw new BusinessException("更新失败") ;
            }
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void deleteExcExchangeRecord(String id) throws BusinessException {
        try {
            long num = excExchangeRecordDAO.deleteById(id);
            if(num == 0) {
                throw new BusinessException("删除失败") ;
            }
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }
}
